﻿/**
 * 
 * @file FITKVAOneXMLWriter.h
 * @brief  VAOne XML文件写入类
 * @author LiBaojun (libaojunqd@foxmail.com)
 * @date 2024-10-11
 * 
 */
#ifndef _FITKVAONE_XML_WRITER_H___
#define _FITKVAONE_XML_WRITER_H___

#include "FITK_Interface/FITKInterfaceIO/FITKAbstractRapidXMLWriter.h"
#include "FITK_Kernel/FITKAdaptor/FITKIOAdaptorFactory.h"

namespace rapidxml
{
    template<class Ch>
    class xml_node;
}

namespace VAOne
{
    class FITKVAOneXMLIOInterface;
    /**
     * @brief VAOne XML写出
     * @author LiBaojun (libaojunqd@foxmail.com)
     * @date 2024-10-11
     */
    class FITKVAOneXMLWriter : public Interface::FITKAbstractRapidXMLWriter
    {
    public:
        /**
         * @brief Construct a new FITKVAOneXMLWriter object
         * @param[i]  interface      组件指针，可传递参数
         * @param[o]  isSuccess      是否执行成功
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-11
         */
        explicit FITKVAOneXMLWriter(FITKVAOneXMLIOInterface* interface, bool & isScuccess);
        /**
         * @brief Destroy the FITKVAOneXMLWriter object
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-11
         */
        virtual ~FITKVAOneXMLWriter() = default;
        /**
         * @brief 执行写出
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-11
         */
        void run() override;
    private:
        /**
         * @brief writeNodes  写入Model数据
         * @param node[i]      xml节点
         * @author  lilongyuan (lilongyuan@diso.cn)
         * @date    2025-01-03
         */
        bool writeModel(rapidxml::xml_node<char> *node);
        /**
         * @brief     适配器写出操作
         * @param[i]  nodeName 子节点名称，node Model节点
         * @return    是否执行成功
         * @author    lilongyuan (lilongyuan@diso.cn)
         * @date      2025-02-24
         */
        bool adaptorWrite(QString nodeName, rapidxml::xml_node<char> *node);
    private:
        /**
         * @brief 打印控制台消息
         * @param[i] level 打印级别 1 normal 2 warning 3error
         * @param[i] str 打印的信息
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-03-08
         */
        void consoleMessage(int level, const QString& str) override;
        /**
        * @brief 将 QString 转换为 char*-（该函数后期会修改）
        * @param[in] qStr 要转换的 QString 对象
        * @return char* 返回指向动态分配的 char* 字符串
        * @throws std::runtime_error 如果字符串复制失败
        * @author lilongyuan (lilongyuan@diso.cn)
        * @date 2025-01-03
        */
        char* copyQStringToChar(const QString& qStr);
        /**
        * @brief   写入属性值
        * @param   node        对应节点
        * @param   attrName    属性名称
        * @param   value       字符串数值
        * @return  写入状态
        * @author  lilongyuan (lilongyuan@diso.cn)
        * @date    2025-01-03
        */
        bool writeAttribute(rapidxml::xml_node<char>* node, QString attrName, QString value);
    private:
        /**
         * @brief 组件对象指针
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-11
         */
        FITKVAOneXMLIOInterface* _compInterface{};
        /**
         * @brief 是否执行成功
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-10-11
         */
        bool & _isSuccess;
    };
}
#endif
